﻿using System;
using System.Data;
using System.IO;
using MyClever.Lib;

namespace MyClever.DefaultPlugins
{
    public class CreateDirectories : MissionPlugin
    {
        [Package(Direction.Input, "Defines the base paths, in which you like to create new directories.")]
        enum BaseDirectories
        {
            [Column(typeof(string), "The path in which you like to create new directories.",
                DefaultValue = "C:\\")]
            PathName
        }

        [Package(Direction.Input, "Defines the new directory names, you like to create.")]
        enum NewDirectories
        {
            [Column(typeof(string), "The directory name you like to create.")]
            DirectoryName
        }

        [Plugin(PluginDevStatus.Production, "Creates some new directories in the given directories.")]
        public CreateDirectories()
        {
        }

        public override void Initialize()
        {

            //This is the first Function called by the host...
            //Put anything needed to start with here first
        }

        public override void Dispose()
        {
            //Put any cleanup code in here for when the program is stopped
        }

        /// <summary>
        /// Generate new Source-content.
        /// </summary>
        protected override void Work()
        {
            DataTableReader baseDirectories = this.GetDataReader(typeof(BaseDirectories));
            while (baseDirectories.Read())
            {
                string basePath = baseDirectories[BaseDirectories.PathName.ToString()].ToString();
                this.AddNewLoggingMessage(typeof(BaseDirectories), String.Format("go to base directory:{0}", basePath));

                DataTableReader newDirectories = this.GetDataReader(typeof(NewDirectories));
                while (newDirectories.Read())
                {
                    this.AddNewLoggingMessage(typeof(NewDirectories), String.Format("create new directory:{0}", newDirectories[NewDirectories.DirectoryName.ToString()].ToString()));

                    Directory.CreateDirectory(basePath + "\\" + newDirectories[NewDirectories.DirectoryName.ToString()].ToString());
                }
            }
        }
    }
}
